import os, sys

sys.path.insert(0, '.')
_WD = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
os.chdir(_WD)


def install_cxfreeze():
    try:
        import pip
    except AttributeError:
        print("Can't start pip. Make sure you are running this script in an "
              "actual console (i.e. not IDLE).")
        return

    pip.main(['install', 'cx_Freeze'])

    print("Installation attempted. Please restart to verify success.")


try:
    from cx_Freeze import setup, Executable
except ImportError:
    print("Did not detect cx_Freeze.")
    if input("Install? (y/n) ").lower().strip() == 'y':
        install_cxfreeze()
else:
    if len(sys.argv) == 1:
        print("[ERROR] Nothing specified.")
        print("Please use `freeze.py build` to build.")

    main_exe = Executable(
        "main.py",
        base='Win32GUI',
        targetName="pymaze.exe",
        targetDir="dist"
    )

    build_exe_options = {
        'include_files': ['ui', 'res', 'copying.txt',
                          'license.txt', 'contrib.txt'],
        'optimize': True,
        'compressed': True,
        'build_exe': "dist"
    }

    setup(
        version="0.1",
        description="A maze game.",
        author="SJAM CS Club",
        name="Pymaze",

        options={
            "build_exe": build_exe_options
        },

        executables=[main_exe]
    )

input('[Press Return to continue...]')
